package com.lujianfei.business.ui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import com.lujianfei.business.base.BaseMenuWindow;
import com.lujianfei.business.beans.Location;
import com.lujianfei.business.drawobject.MainLogicDrawObject;
import com.lujianfei.business.widget.DrawPanel;
import com.lujianfei.lib.sdautolayout.impl.SDAutoLayout;

public class MainFrame extends BaseMenuWindow {

	DrawPanel mDrawPanel = new DrawPanel();
	@Override
	protected List<MenuBean> getMenuBean() {
		List<MenuBean> menuBeans = new ArrayList<>();
		List<MenuBean> menuOperation = new ArrayList<>();
		menuBeans.add(new MenuBean.Builder().setName("操作").setChilds(menuOperation).create());
		menuOperation.add(new MenuBean.Builder().setName("开始运行").setActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				mDrawPanel.start();
			}
		}).create());
		menuOperation.add(new MenuBean.Builder().setName("暂停").setActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				mDrawPanel.pause();
			}
		}).create());
		menuOperation.add(new MenuBean.Builder().setName("停止").setActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				mDrawPanel.stop();				
			}
		}).create());
		menuOperation.add(new MenuBean.Builder().setName("退出").setActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				mDrawPanel.stop();
				exit();
			}
		}).create());
		return menuBeans;
	}

	public MainFrame() {
		setTitle("创业仿真器");
		mDrawPanel.setBackground(Color.black);
		mDrawPanel.addDrawObject(new MainLogicDrawObject.Builder().setSuperMarket(new Location(20, 20), getWidth()-60	, getHeight()-120).create());
		add(mDrawPanel);
		SDAutoLayout.forComponent(mDrawPanel).widthIs(getWidth()).heightIs(getHeight());
	}
}
